package com.hope.hotel.controller;

import com.hope.hotel.common.Result;
import com.hope.hotel.entity.DAO.HotelNewDAO;
import com.hope.hotel.entity.DAO.LoginDAO;
import com.hope.hotel.entity.po.Hotel;
import com.hope.hotel.service.AdminService;
import com.hope.hotel.service.HotelService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @作者 LH
 * @日期 2025/5/26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin")
public class AdminController {

    private final AdminService adminService;
    private final HotelService hotelService;
    @PostMapping("/login")
    public Result adminLogin(@RequestBody LoginDAO loginDAO){
       return adminService.adminLogin(loginDAO);
    }

    @GetMapping("/hotelInfo")
    public Result getAdminInfo(HttpServletRequest request) {
        String adminId = (String)request.getAttribute("adminId");
        System.out.println("adminId = " + adminId);
        return hotelService.getAdminHotelInfo(adminId);
    }

    @PostMapping("/create-hotel")
    public Result createHotel(@RequestBody HotelNewDAO hotelNewDAO, HttpServletRequest request) {
        String adminId = (String)request.getAttribute("adminId");
        System.out.println("adminId = " + adminId);
        return hotelService.createHotel(hotelNewDAO,adminId);
    }

    @PostMapping("/update-hotel")
    public Result updateHotel(@RequestBody HotelNewDAO hotel, HttpServletRequest request) {
        String adminId = (String)request.getAttribute("adminId");
        return hotelService.updateHotel(hotel,adminId);
    }
}
